const path = require('path')
const Webpack = require('webpack')
const VueLoaderPlugin = require('vue-loader/lib/plugin')

const HtmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
  mode: 'none',
  entry: './src/main.js',
  output: {
    filename: 'js/[name].boundle.js', //输出的文件名
    path: path.join(__dirname, 'dist')
  },
  module: {
    rules: [
      // 编写模块匹配规则，执行对应的 loader
      {
        //test设置需要匹配的文件类型，支持正则
        test: /\.vue$/,
        //use表示该文件类型需要调用的loader
        use: {
          loader: 'vue-loader',
          options: {
            attributes: {
              list: [{
                tag: 'img',
              },{tag: 'link',
                attribute: 'href',
                type: 'src'}]
            }
          }
        }
      },
      {
        test: /\.js$/,
        use: 'eslint-loader',
        exclude: /node_modules/ //exclude为排除项，意思是不要处理node_modules中的js文件
      },
      {
        test: /\.js$/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['@babel/preset-env']
          }
        }
      },
      {
        test: /\.css$/,
        use: ['style-loader','css-loader'],
        exclude: /node_modules/
      },
      {
        test: /\.less$/,
        use: ['style-loader','css-loader','less-loader'],
        exclude: /node_modules/
      },
      {
        test: /\.jpg|jpeg|png|gif|bmp|ttf|eot|svg|woff|woff2$/,
        use: {
          loader: 'url-loader',
          options: {
            outputPath: 'img',
            limit: 10 * 1024,//limit用来设置字节数，只有小于limit值的图片，才会转换为base64图片
            esModule: false
          }
        }
      }
    ]
  },
  plugins: [
    new Webpack.DefinePlugin({
      BASE_URL: JSON.stringify('./')
    }),
    new VueLoaderPlugin(),
    new HtmlWebpackPlugin({
      title: 'webpack Vue',
      filename: 'index.html',
      template: './public/index.html'
    })
  ]
}